/**
 ****************************************************************
 * Copyright (c) 2011 –苏州埃涅加克电子信息科技有限公司
 * Title: 
 * Description: 
 **************************************************************** 
 * 2011-12-02  V1.0  Li CaiRong    New Files for 
 */

package com.engc.common.utils;

import java.io.Serializable;
import java.util.Locale;
import java.util.ResourceBundle;

public class MessageManager implements Serializable{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	protected String messagePropertyFile;
	protected ResourceBundle bundle;

	public MessageManager(String messageFile) {
		this.messagePropertyFile = messageFile;
	}

	public String getMessage(String tag) {
		try{
			if (this.bundle == null) {
				this.bundle = getResourceBundle(this.messagePropertyFile);
				if (this.bundle == null) {
					return "";
				}
			}
			return this.bundle.getString(tag);
		}catch(Exception e){
			e.printStackTrace();
			return tag;
		}
		
	}

	private ResourceBundle getResourceBundle(String baseName) {
		return getResourceBundle(baseName, null);
	}

	private ResourceBundle getResourceBundle(String baseName, Locale locale) {
		if (locale == null) {
			return ResourceBundle.getBundle(baseName);
		}
		return ResourceBundle.getBundle(baseName, locale);
	}

}
